namespace Demo.Public.Extensions;
using System;
using System.Threading;
using System.Threading.Tasks;

public static class TaskExtension
{
    public static async void Await(this Task task, Action? onCompleted = null, Action<Exception> onError = null)
    {
        if (task == null) throw new ArgumentNullException(nameof(task));


            try
            {
                await task;
                onCompleted?.Invoke();
            }
            catch (Exception ex)
            {
                onError?.Invoke(ex);
            }

    }
    
}
